﻿using System;
using NUnit.Core;
using NUnit.Core.Extensibility;

namespace SqlTdd.Addin
{
    [NUnitAddin(Name = "SqlTdd TestRunner Addin", Description = "NUnit Addin for SqlTdd")]
    public class TestRunner : IAddin, ISuiteBuilder
    {
        #region IAddin Members

        public bool Install(IExtensionHost host)
        {
            IExtensionPoint builders = host.GetExtensionPoint("SuiteBuilders");
            if (builders == null)
                return false;

            builders.Install(this);
            return true;
        }

        #endregion

        #region ISuiteBuilder Members

        public bool CanBuildFrom(Type type)
        {
            return Reflect.HasAttribute(type, "SqlTdd.Attributes.TestCatalogAttribute", false);
        }

        public Test BuildFrom(Type type)
        {
            return new TestCatalogBuilder(type);
        }

        #endregion
    }
}